function foregroundImage = extractForeground(frame, backgroundImage, foregroundThreshold)
    % Estimates the background as the incremental average image
    changed_part = double(frame) - double(backgroundImage);
    
    [H, W] = size(frame);
    
    foregroundImage = zeros(H,W);
        
    for j = 1:H
        for k = 1: W;
            if (abs(changed_part(j, k)) > foregroundThreshold)
                foregroundImage(j,k) = 1;
            end
        end
    end

end

